package doantotnghiep.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.NamedNativeQuery;

@Entity
@NamedNativeQuery(name="getCurentPurchase", query="call getCurentPurchase();",resultClass = PurchaseOrder.class)
@Table(name = "DonDatHang")
public class PurchaseOrder {
   
	private int orderID;
	private String orderedDate;
	private String deliveryDate;
	private String deliveryLocation;
	private int isExported;
	
	@Column(name = "DaXuatKho")
	public int getIsExported() {
		return isExported;
	}

	public void setIsExported(int isExported) {
		this.isExported = isExported;
	}
	
	@Id
	@GeneratedValue
	@Column(name="MaDDH")
	public int getOrderID() {
		return orderID;
	}
	
	public void setOrderID(int orderID) {
		this.orderID = orderID;
	}
	
	@Column(name ="NgayDatHang")
	public String getOrderedDate() {
		return orderedDate;
	}
	
	public void setOrderedDate(String orderedDate) {
		this.orderedDate = orderedDate;
	}
	
	@Column(name = "NgayGiaoHang")
	public String getDeliveryDate() {
		return deliveryDate;
	}
	
	public void setDeliveryDate(String deliveryDate) {
		this.deliveryDate = deliveryDate;
	}
	
	@Column(name="NoiGiaoHang")
	public String getDeliveryLocation() {
		return deliveryLocation;
	}
	
	public void setDeliveryLocation(String deliveryLocation) {
		this.deliveryLocation = deliveryLocation;
	}
	
	private Customer customer;

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "MaKH")
	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	private Staff staff;
	
	@ManyToOne
	@JoinColumn(name="MaNV")
	public Staff getStaff() {
		return staff;
	}

	public void setStaff(Staff staff) {
		this.staff = staff;
	}
	//@Fetch(FetchMode.JOIN)
	private Set<PurchaseOrderDetail> purchaseOrderDetails = new HashSet<PurchaseOrderDetail>();
	
	@OneToMany(mappedBy = "purchaseOrder", fetch = FetchType.LAZY) 
	public Set<PurchaseOrderDetail> getPurchaseOrderDetails() {
		return purchaseOrderDetails;
	}	
	public void setPurchaseOrderDetails(Set<PurchaseOrderDetail> purchaseOrderDetails) {
		this.purchaseOrderDetails = purchaseOrderDetails;
	}
	
}
